package com.dayou.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.dayou.bean.SysDept;
import com.dayou.service.ISysDeptService;
import com.dayou.common.core.controller.BaseController;
import com.dayou.common.core.page.TableDataInfo;
import com.dayou.common.core.domain.AjaxResult;
import com.dayou.common.utils.poi.ExcelUtil;

/**
 * 达幽系统集成框架 - 部门 信息操作处理
 *
 * @author dayou
 * @date 2020-04-24
 */
@Controller
@RequestMapping("/sysDept")
@Api(value="部门管理",description = "部门管理")
public class SysDeptController extends BaseController {
    private String prefix = "sysUser";
    @Autowired
    private ISysDeptService sysDeptService;

    @GetMapping()
    public String login() {
        return prefix + "/sysDept";
    }

    /**
     * 查询所有未删除达幽系统集成框架 - 部门列表
     */
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询所有未删除的部门")
    public TableDataInfo list(@RequestBody SysDept sysDept) {
        sysDept.setIsDeleted(0);
        startPage();
        List<SysDept> list = sysDeptService.selectSysDeptList(sysDept);
        return getDataTable(list);
    }

    /**
     * 查询所有已删除达幽系统集成框架 - 部门列表
     */
    @PostMapping("/listDeleted")
    @ResponseBody
    @ApiOperation(value = "查询所有已删除的部门")
    public TableDataInfo listDeleted(@RequestBody SysDept sysDept) {
        sysDept.setIsDeleted(1);
        startPage();
        List<SysDept> list = sysDeptService.selectSysDeptList(sysDept);
        return getDataTable(list);
    }

    /**
     * 伪删除达幽系统集成框架 - 部门
     */
    @PostMapping("/fakeDelete")
    @ResponseBody
    @ApiOperation(value = "通过id(组)伪删除部门")
    public AjaxResult fakeDelete(String ids) {
        return toAjax(sysDeptService.fakeDeleteSysDeptByIds(ids));
    }

    /**
     * 恢复达幽系统集成框架 - 部门
     */
    @PostMapping("/resume")
    @ResponseBody
    @ApiOperation(value = "通过id(组)恢复部门")
    public AjaxResult resume(String ids) {
        return toAjax(sysDeptService.resumeSysDeptByIds(ids));
    }

    /**
     * 查询所有达幽系统集成框架 - 部门列表
     */
    @PostMapping("/listAll")
    @ResponseBody
    @ApiOperation(value = "查询所有部门")
    public TableDataInfo listAll(@RequestBody SysDept sysDept) {
        startPage();
        List<SysDept> list = sysDeptService.selectSysDeptList(sysDept);
        return getDataTable(list);
    }


    /**
     * 导出达幽系统集成框架 - 部门列表
     */
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation(value = "导出部门信息")
    public AjaxResult export(@RequestBody SysDept sysDept) {
        List<SysDept> list = sysDeptService.selectSysDeptList(sysDept);
        ExcelUtil<SysDept> util = new ExcelUtil<SysDept>(SysDept.class);
        return util.exportExcel(list, "部门信息");
    }

    /**
     * 新增保存达幽系统集成框架 - 部门
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody SysDept sysDept) {
        return toAjax(sysDeptService.insertSysDept(sysDept));
    }

    /**
     * 修改保存达幽系统集成框架 - 部门
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody SysDept sysDept) {
        return toAjax(sysDeptService.updateSysDept(sysDept));
    }

    /**
     * 删除达幽系统集成框架 - 部门
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sysDeptService.deleteSysDeptByIds(ids));
    }

}
